<template>
  <div class="app-container">
    <el-form ref="placeCodeForm" v-loading="formLoading" :rules="rules" :model="form" label-position="top">
      <el-row type="flex" :gutter="20">
        <el-col :span="24">
        </el-col>
      </el-row>
      <el-row type="flex" :gutter="20">
        <el-col :span="24">
          <el-form-item label="专业" prop="schoolName" style="width: 400px">
            <el-input v-model="form.speciality" placeholder="请输入专业" clearable  />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="人数" prop="schoolName" style="width: 400px">
            <el-input v-model="form.number" placeholder="请输入人数" clearable  />
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  </div>
</template>

<script>
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import {bakGetMajorByIdApi, editMajorApi} from "@/api/school";
export default {
  components: { Editor, Toolbar },
  name: 'PlaceCodeDetail',
  data(){
    return{
      editor: null,
      liveTime:[],
      comList:{},
      userList:{},
      publishList:{},
      toolbarConfig: {
        excludeKeys: [
          // 排除菜单组，写菜单组 key 的值即可
          'group-video' // 去掉视频
        ]
      },
      editorConfig: { MENU_CONF: {}, placeholder: '' },
      mode: 'default',
      uploadUrl: process.env.VUE_APP_UPLOAD_API,
      dialogImageUrl: '',
      dialogVisible: false,
      form: {
        id: null,
        schoolName:'',
        introduce:'',
        logo: '',
        publishIds: '',
        schoolId: 0
      },
      rules: {
        speciality: [{ required: true, trigger: 'blur', message: '请输入专业' }],
        number: [{ required: true, trigger: 'blur', message: '请填写人数' }],
      },
      formLoading: false,
    }
  },
  props:['id','closeDialog','schoolId'],
  methods:{

    submit(){
      this.$refs.placeCodeForm.validate(valid => {
        if (valid) {
          const loading=this.$loading({
            text:'提交中'
          })
          if(this.form.id==null)
          {
            this.form.id = 0;
          }
          const form=JSON.parse(JSON.stringify(this.form));
          form.schoolId = this.schoolId;
          console.log(form.schoolId)
          editMajorApi(form).then((res)=>{
            this.$message.success('保存成功');
            this.closeDialog(0);
          }).catch(()=>{
            this.$message.error('保存失败');
          }).finally(()=>{
            loading.close();
          })
        } else {
          return false
        }
      })
    },
    getDetail(){
      bakGetMajorByIdApi({id:this.id}).then((res)=>{
        this.form=res;
      }).finally(()=>{
        this.formLoading=false;
      })
    },
  },
  watch: {

  },
  mounted() {
    if(this.id){
      this.getDetail();
    }
  console.log(this.schoolId)
  },

}
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #c5c5c5;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;

}
.w-e-bar.w-e-bar-show.w-e-toolbar{
  border: 1px solid;
}
.w-e-scroll{
  border: 1px solid;
}
</style>
<style scoped>
/*
*让select撑开
*/
.el-select,.el-cascader{
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed #c5c5c5;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;

}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
